﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class Flow_Info_CreateWork : System.Web.UI.Page {
    public List<Flow_NewFlowStep> list_step = null;
    private int new_flow_id;
    protected void Page_Load(object sender, EventArgs e) {
        if(!Page.IsPostBack) {
            if(Request.QueryString.Get("FLOW_ID") != null) {
                new_flow_id = int.Parse(Request.QueryString.Get("FLOW_ID"));
                Flow_NewFlow_Service fnf_service = new Flow_NewFlow_Service();
                Flow_NewFlowStep_Service fnfs_service = new Flow_NewFlowStep_Service();
                list_step = fnfs_service.FindStepsByNewFlowId(new_flow_id);
                Flow_NewFlow fnf = fnf_service.FindByNewFlowId(new_flow_id);
                if(fnf != null) {
                    this.DdlNewFlowName.Items.Add(new ListItem(fnf.NewFlow_name, fnf.NewFlowl_id.ToString()));
                    DdlNewFlowName.SelectedIndex = 0;
                    this.TxtNewWorkName.Text = fnf.NewFlow_name + "(" + DateTime.Now.ToString() + ")";
                }
                ViewState["new_flow_id"] = new_flow_id;
            }
        }
    }
    protected void BtnNew_Click(object sender, EventArgs e) {
        if(ViewState["new_flow_id"] != null) {
            new_flow_id = (int) ViewState["new_flow_id"];
        }
        User curLoginUser = (User) Session["user"];
        Flow_NewWork_Service fnf_service = new Flow_NewWork_Service();
        string newWorkName = Request.Form.Get(this.TxtNewWorkName.ClientID);
        fnf_service.CreateWork(curLoginUser.LoginName, new_flow_id, newWorkName);
        ViewState["new_flow_id"] = new_flow_id;
       //ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "$(\"Windows:parent:parent #tab1\").css('font-size','19px')", true);
        ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "window.parent.location = 'WillTransactWork.aspx'", true);
    }
    protected void BtnBack_Click(object sender, EventArgs e) {
        ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "window.parent.location = 'CreateWorkIndex.aspx'", true);
    }
}
